using System.ComponentModel.DataAnnotations.Schema;
using System.Data.Entity.ModelConfiguration;

namespace InduMall.Core.Models.Mapping
{
    public class ProductMap : EntityTypeConfiguration<Product>
    {
        public ProductMap()
        {
            // Primary Key
            this.HasKey(t => t.ProductId);

            // Properties
            this.Property(t => t.ProductName)
                .IsRequired()
                .HasMaxLength(32);

            this.Property(t => t.ProductImage)
                .IsRequired()
                .HasMaxLength(255);

            this.Property(t => t.ProductDescription)
                .IsRequired();

            this.Property(t => t.ProductNumber)
                .IsRequired()
                .HasMaxLength(64);

            this.Property(t => t.Brand)
                .HasMaxLength(25);

            this.Property(t => t.SeoWord)
                .HasMaxLength(500);

            this.Property(t => t.Sku)
                .IsRequired()
                .HasMaxLength(60);

            // Table & Column Mappings
            this.ToTable("Product");
            this.Property(t => t.ProductId).HasColumnName("ProductId");
            this.Property(t => t.ProductName).HasColumnName("ProductName");
            this.Property(t => t.ProductPrice).HasColumnName("ProductPrice");
            this.Property(t => t.ProductImage).HasColumnName("ProductImage");
            this.Property(t => t.ProductDescription).HasColumnName("ProductDescription");
            this.Property(t => t.CategoryId).HasColumnName("CategoryId");
            this.Property(t => t.ProductNumber).HasColumnName("ProductNumber");
            this.Property(t => t.Brand).HasColumnName("Brand");
            this.Property(t => t.SeoWord).HasColumnName("SeoWord");
            this.Property(t => t.Sku).HasColumnName("Sku");
            this.Property(t => t.ProductType).HasColumnName("ProductType");

            // Relationships
            this.HasMany(t => t.Product1)
                .WithMany(t => t.Products)
                .Map(m =>
                    {
                        m.ToTable("RelatedProduct");
                        m.MapLeftKey("ProductId");
                        m.MapRightKey("RelatedProductId");
                    });


        }
    }
}
